﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Double;
namespace NumericalAnalysis.DataInterpolation.MathNetExample
{
    internal class Stage_00_TestDemo
    {
        public static void Run()
        {
            Matrix<double> A = DenseMatrix.OfArray(new double[,] {
                {1,1,1,1},
                {1,2,3,4},
                {4,3,2,1}});
            Vector<double>[] nullspace = A.Kernel();

            // verify: the following should be approximately (0,0,0)
            // (A * (2 * nullspace[0] - 3 * nullspace[1]))
            Console.WriteLine(nullspace[0]);
            Console.WriteLine(nullspace[1]);

            var result = A * (2 * nullspace[0] - 3 * nullspace[1]);
            Console.WriteLine(
                "verify:   should be approximately (0,0,0)\n" +
                result);
        }

        public static void MatrixDefine()
        {
            //矩阵的定义和初始化
            DenseMatrix matrix1 = new DenseMatrix(3);//3维方阵
            DenseMatrix matrix2 = new DenseMatrix(2, 2);  //2维方阵
            DenseMatrix matrix3 = new DenseMatrix(2, 3); //2×3矩阵
            DenseMatrix matrix4 = new DenseMatrix(3, 2); //3×2矩阵
            var array = new double[6] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 };
            DenseMatrix matrix5 = new DenseMatrix(2, 3, array); //2×3矩阵，所有值为3.0
            Console.WriteLine(matrix5.Row(1, 2, 1));
            DenseMatrix matrixI = DenseMatrix.CreateIdentity(5); //5维单位矩阵
            //利用C#中的double[,]直接创建,2×3矩阵
            double[,] d_matrix = new double[2, 3];
            // var matrix6 = new DenseMatrix(d_matrix);
            var matrix6 = DenseMatrix.OfArray(d_matrix);
        }

    }
}
